$(document).ready(function () {
    //获取订单号
    if (getCookie("order") == "") {
        alert("您最近没有需要支付的订单，去购物吧");
        location.href = "list.html";
    }
    let order_id = getCookie("order");
    $.ajax({
        type: "get",
        url: "http://localhost:3301/order?id=" + order_id,
        async: false,
        success: function (e) {
            let order = e[0];
            console.log(order);
            $("#order_su").html(order.order_sn);
            $("#total_price").html("￥" + order.total_amount);
            $(`#${order.pay_code}`).css("border", "2px solid rgb(228, 57, 60)");
        }
    })
    $("#pay").click(function () {
        $.ajax({
            type:"get",
            url:"http://localhost:3301/order?id="+order_id,
            async:false,
            success:function(e){
                let order = e[0];
                order.order_status = 1;
                $.ajax({
                    type:"put",
                    url:"http://localhost:3301/order/"+order.id,
                    data:order,
                    async:false,
                    success:function(e){
                        console.log("支付成功");
                    }
                })
            }
        })
    })
})